# -*- coding:UTF-8 -*- ＃
'''
Created on 2013-5-5

@author: YANGCHENLONG
'''
from Queue import Queue
import threading
from UrlCrawler import *
from ConfigParser import ConfigParser

if __name__ == '__main__':
    config = ConfigParser();
    config.read("sites.ini")
    sections = config.sections()
    print sections
    
    opts = config.options('subject-entrance')
    print opts
    
    items = config.items('subject-entrance')
    
    mainpage = config.get('site', 'mainpage')  #str(raw_input('Enter the mainpage:'))
    for subject in opts:
        print config.get('subject-entrance', subject)
        num = 10                               #int(raw_input('Enter thread num:'))
        pnum =  1000                          #int(raw_input('Enter download pages:'))
        startpage = config.get('subject-entrance', subject) #str(raw_input('Enter start page:'))
        queue = Queue()
        key = Queue()
        inqueue = Queue()
        list = NewList()
        thlist = []
        
        Flcok = threading.RLock()
        for i in range(num):
            th = reptile('th' + str(i), queue, key, Flcok)
            thlist.append(th)
            
        pro = proinsight(key, list, mainpage, startpage, inqueue)
        pro.start()
        
        for i in thlist:
            i.start()
        
        queue.put(startpage)
        for i in range(pnum):
            queue.put(inqueue.get())
        
        for i in range(num):
            queue.put(None)
 
